package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/market"
	"git.900sui.cn/kc/rpcinterface/client/order"
	market2 "git.900sui.cn/kc/rpcinterface/interface/market"
	"github.com/streadway/amqp"
)

//订单支付成功，业务处理
func main() {
	mOrder := new(order.OrderPay).Init()
	defer mOrder.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("order.log.orderPaySuc"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("order.queue.orderPaySuc"), func(msg amqp.Delivery) {
		orderSn := string(msg.Body)

		// 共享卡支付成功回调
		rpcMarket := new(market.Share).Init()
		defer rpcMarket.Close()
		args := market2.ArgsGetShareCardConsumeLog{
			ConsumeSn: orderSn,
		}
		var replyMarket market2.ReplyGetShareCardConsumeLog
		// 根据订单号获取共享卡消费记录,是否是共享卡支付。
		err := rpcMarket.GetShareCardConsumeLogInfo(context.Background(),&args, &replyMarket)
		if err != nil {
			utils.Logerr.Printf("共享卡订单支付成功，业务处理任务调用失败，orderSn:%s, err:%s", orderSn, err)
		}
		 var replyConsumePaySuc bool
		if replyMarket.Uid > 0 {
			// 共享消费支付成功回调处理
			err = rpcMarket.ConsumePaySuc(context.Background(),&orderSn, &replyConsumePaySuc)
			if err != nil {
				utils.Logerr.Printf("共享消费支付成功回调处理失败，orderSn:%s, err:%s", orderSn, err)
			}
		}else {
			var reply bool
			err = mOrder.PaySuc(context.Background(), &orderSn, &reply)
			if err != nil {
				utils.Logerr.Printf("订单支付成功，业务处理任务调用失败，orderSn:%s, err:%s", orderSn, err)
			}
		}

	})

	if err != nil {
		utils.Logerr.Printf("订单支付成功任务错误，err: %s", err.Error())
	}
}
